# use normal make for this Makefile
#
# Makefile for building user programs to run on top of Nachos
#
# Several things to be aware of:
#
#    Nachos assumes that the location of the program startup routine (the
# 	location the kernel jumps to when the program initially starts up)
#       is at location 0.  This means: start.o must be the first .o passed 
# 	to ld, in order for the routine "Start" to be loaded at location 0
#

# If you are running on SunOS 5.x machines, uncomment the next line
GCCDIR = /auto/home-scf-22/csci402/testgnu/decstation-ultrix/bin/
LDFLAGS = -T newscript -N
ASFLAGS = -mips1
CPPFLAGS = $(INCDIR)

# if you aren't cross-compiling:
# GCCDIR =
# LDFLAGS = -N -T 0
# ASFLAGS =
# CPPFLAGS = -P $(INCDIR)


CC = $(GCCDIR)gcc
AS = $(GCCDIR)as
LD = $(GCCDIR)ld
CPP = $(GCCDIR)cpp

INCDIR =-I../userprog -I../threads
CFLAGS = -G 0 -c $(INCDIR)

all: halt matmult sort testfiles

start.o: start.s ../userprog/syscall.h
	$(CPP) $(CPPFLAGS) start.s > strt.s
	$(AS) $(ASFLAGS) -o start.o strt.s
	rm strt.s

halt.o: halt.c
	$(CC) $(CFLAGS) -c halt.c
halt: halt.o start.o
	$(LD) $(LDFLAGS) start.o halt.o -o halt.coff
	../bin/coff2noff halt.coff halt

sort.o: sort.c
	$(CC) $(CFLAGS) -c sort.c
sort: sort.o start.o
	$(LD) $(LDFLAGS) start.o sort.o -o sort.coff
	../bin/coff2noff sort.coff sort

matmult.o: matmult.c
	$(CC) $(CFLAGS) -c matmult.c
matmult: matmult.o start.o
	$(LD) $(LDFLAGS) start.o matmult.o -o matmult.coff
	../bin/coff2noff matmult.coff matmult

testfiles.o: testfiles.c
	$(CC) $(CFLAGS) -c testfiles.c
testfiles: testfiles.o start.o
	$(LD) $(LDFLAGS) start.o testfiles.o -o testfiles.coff
	../bin/coff2noff testfiles.coff testfiles

LockTests.o: LockTests.c
	$(CC) $(CFLAGS) -c LockTests.c
LockTests: LockTests.o start.o
	$(LD) $(LDFLAGS) start.o LockTests.o -o LockTests.coff
	../bin/coff2noff LockTests.coff LockTests
	
ForkTest.o: ForkTest.c
	$(CC) $(CFLAGS) -c ForkTest.c
ForkTest: ForkTest.o start.o
	$(LD) $(LDFLAGS) start.o ForkTest.o -o ForkTest.coff
	../bin/coff2noff ForkTest.coff ForkTest

ExecTest.o: ExecTest.c
	$(CC) $(CFLAGS) -c ExecTest.c
ExecTest: ExecTest.o start.o
	$(LD) $(LDFLAGS) start.o ExecTest.o -o ExecTest.coff
	../bin/coff2noff ExecTest.coff ExecTest
	
SimpleTest.o: SimpleTest.c
	$(CC) $(CFLAGS) -c SimpleTest.c
SimpleTest: SimpleTest.o start.o
	$(LD) $(LDFLAGS) start.o SimpleTest.o -o SimpleTest.coff
	../bin/coff2noff SimpleTest.coff SimpleTest
	
AddrSpaceTest.o: AddrSpaceTest.c
	$(CC) $(CFLAGS) -c AddrSpaceTest.c AddrSpaceSub.c
AddrSpaceTest: AddrSpaceTest.o start.o AddrSpaceSub.c
	$(LD) $(LDFLAGS) start.o AddrSpaceTest.o AddrSpaceSub.c -o AddrSpaceTest.coff
	../bin/coff2noff AddrSpaceTest.coff AddrSpaceTest
	
AddrSpaceSub.o: AddrSpaceSub.c
	$(CC) $(CFLAGS) -c AddrSpaceSub.c
AddrSpaceSub: AddrSpaceSub.o start.o
	$(LD) $(LDFLAGS) start.o AddrSpaceSub.o -o AddrSpaceSub.coff
	../bin/coff2noff AddrSpaceSub.coff AddrSpaceSub
	
CondTest.o: CondTest.c
	$(CC) $(CFLAGS) -c CondTest.c
CondTest: CondTest.o start.o
	$(LD) $(LDFLAGS) start.o CondTest.o -o CondTest.coff
	../bin/coff2noff CondTest.coff CondTest
	
NegTest.o: NegTest.c
	$(CC) $(CFLAGS) -c NegTest.c
NegTest: NegTest.o start.o
	$(LD) $(LDFLAGS) start.o NegTest.o -o NegTest.coff
	../bin/coff2noff NegTest.coff NegTest
	
ItoaTest.o: ItoaTest.c
	$(CC) $(CFLAGS) -c ItoaTest.c
ItoaTest: ItoaTest.o start.o
	$(LD) $(LDFLAGS) start.o ItoaTest.o -o ItoaTest.coff
	../bin/coff2noff ItoaTest.coff ItoaTest

mvtest.o: mvtest.c
	$(CC) $(CFLAGS) -DNETWORK -c mvtest.c
mvtest: mvtest.o start.o
	$(LD) $(LDFLAGS) start.o mvtest.o -o mvtest.coff
	../bin/coff2noff mvtest.coff mvtest
	
servertest_wait.o: servertest_wait.c
	$(CC) $(CFLAGS) -DNETWORK -c servertest_wait.c
servertest_wait: servertest_wait.o start.o
	$(LD) $(LDFLAGS) start.o servertest_wait.o -o servertest_wait.coff
	../bin/coff2noff servertest_wait.coff servertest_wait
	
servertest_signal.o: servertest_signal.c
	$(CC) $(CFLAGS) -DNETWORK -c servertest_signal.c
servertest_signal: servertest_signal.o start.o
	$(LD) $(LDFLAGS) start.o servertest_signal.o -o servertest_signal.coff
	../bin/coff2noff servertest_signal.coff servertest_signal

multi_wait.o: multi_wait.c
	$(CC) $(CFLAGS) -c multi_wait.c
multi_wait: multi_wait.o start.o
	$(LD) $(LDFLAGS) start.o multi_wait.o -o multi_wait.coff
	../bin/coff2noff multi_wait.coff multi_wait
	
multi_signal.o: multi_signal.c
	$(CC) $(CFLAGS) -c multi_signal.c
multi_signal: multi_signal.o start.o
	$(LD) $(LDFLAGS) start.o multi_signal.o -o multi_signal.coff
	../bin/coff2noff multi_signal.coff multi_signal
	
AcquireExit.o: AcquireExit.c
	$(CC) $(CFLAGS) -c AcquireExit.c
AcquireExit: AcquireExit.o start.o
	$(LD) $(LDFLAGS) start.o AcquireExit.o -o AcquireExit.coff
	../bin/coff2noff AcquireExit.coff AcquireExit
	
MultiCineplex.o: MultiCineplex.c
	$(CC) $(CFLAGS) -c MultiCineplex.c
MultiCineplex: MultiCineplex.o start.o
	$(LD) $(LDFLAGS) start.o MultiCineplex.o -o MultiCineplex.coff
	../bin/coff2noff MultiCineplex.coff MultiCineplex
	
cineplex.o: cineplex.c customer.c manager.c lobby.c movietech.c line.c ticketclerk.c foodclerk.c tickettaker.c cineplex.h customer.h manager.h lobby.h movietech.h cineplex.h ticketclerk.h foodclerk.h tickettaker.h
	$(CC) $(CFLAGS) -c cineplex.c customer.c manager.c lobby.c movietech.c line.c ticketclerk.c foodclerk.c tickettaker.c 
cineplex: cineplex.o customer.o manager.o lobby.o movietech.o line.o ticketclerk.o foodclerk.o tickettaker.o start.o
	$(LD) $(LDFLAGS) cineplex.o customer.o manager.o lobby.o movietech.o line.o ticketclerk.o foodclerk.o tickettaker.o start.o -o cineplex.coff
	../bin/coff2noff cineplex.coff cineplex
	
clean:
	rm -f *.o *.coff
